import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { moduleConfig } from './module.config'
import { createSvgIconsPlugin } from "vite-plugin-svg-icons"

// 放弃模块联邦，使用传统库模式打包
export default defineConfig({
    plugins: [
        vue(),
        createSvgIconsPlugin({
            iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
            symbolId: "i-[dir]-[name]"
        })
    ],
    build: {
        outDir: moduleConfig.getOutputDirectory(),
        emptyOutDir: true,
        target: 'es2022',
        lib: {
            entry: path.resolve(__dirname, 'src/index.ts'),
            name: 'LoginModule',
            fileName: 'moduleEntry',
            formats: ['es']
        },
        rollupOptions: {
            // 完全排除所有外部依赖，避免任何冲突
            external: [
                'vue',
                'vue-router',
                'pinia',
                'element-plus',
                '@element-plus/icons-vue',
                'lodash',
                'axios',
                /^element-plus\/.*$/,
                /^@element-plus\/.*$/
            ],
            output: {
                globals: {
                    vue: 'Vue',
                    'vue-router': 'VueRouter',
                    pinia: 'Pinia',
                    'element-plus': 'ElementPlus',
                    'lodash': '_',
                    'axios': 'axios'
                },
                exports: 'named',
                interop: 'auto',
                assetFileNames: 'assets/[name][extname]',
                chunkFileNames: 'assets/[name].js'
            }
        },
        minify: false,
        sourcemap: false,
        assetsInlineLimit: 0 // 确保SVG等资源单独打包
    },
    assetsInclude: ['**/*.svg']
})